From ae1962d7598a4e38ec81f9e3dfb949c159fb0214 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 15 Aug 2014 18:25:12 -0700 Subject: [PATCH] Allow updating transitive deps Previously `cargo update foo` would only update the package `foo` if it were a direct dependency of the local package. This meant that to update a transitive dependency you would have to update the top-level dependency. This commit adds the ability to update any dependency by name, regardless of where it is in the dependency graph. This commit is a bit lossy in terms of behavior. We are guaranteed that the set of immediate dependencies for any one package have unique names, but not for the entire package graph. This means that when you invoke `cargo update foo` it could possibly update two packages named `foo`. I believe this behavior to be acceptable for now and we can add a more stringent update syntax later (something like `cargo update --namespace foo bar`). I believe we'll always want this CLI usage, however. --- src/cargo/ops/cargo_generate_lockfile.rs | 9 ++------- tests/test_cargo_compile_git_deps.rs | 6 ++++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cargo/ops/cargo_generate_lockfile.rs b/src/cargo/ops/cargo_generate_lockfile.rs index 9bf5c1260..1e10f53d3 100644 --- a/src/cargo/ops/cargo_generate_lockfile.rs +++ b/src/cargo/ops/cargo_generate_lockfile.rs @@ -63,13 +63,8 @@ pub fn update_lockfile(manifest_path: &Path, let sources = match to_update { Some(name) => { let mut to_avoid = HashSet::new(); - match resolve.deps(package.get_package_id()) { - Some(deps) => { - for dep in deps.filter(|d| d.get_name() == name.as_slice()) { - fill_with_deps(&resolve, dep, &mut to_avoid); - } - } - None => {} + for dep in resolve.iter().filter(|d| d.get_name() == name.as_slice()) { + fill_with_deps(&resolve, dep, &mut to_avoid); } resolve.iter().filter(|pkgid| !to_avoid.contains(pkgid)) .map(|pkgid| pkgid.get_source_id().clone()).collect() diff --git a/tests/test_cargo_compile_git_deps.rs b/tests/test_cargo_compile_git_deps.rs index cfb4c87d0..5219e4f79 100644 --- a/tests/test_cargo_compile_git_deps.rs +++ b/tests/test_cargo_compile_git_deps.rs @@ -678,6 +678,12 @@ test!(update_with_shared_deps { {compiling} foo v0.5.0 ({dir})\n", git = git_project.url(), compiling = COMPILING, dir = p.url()))); + + // We should be able to update transitive deps + assert_that(p.process(cargo_dir().join("cargo-update")).arg("bar"), + execs().with_stdout(format!("{} git repository `{}`", + UPDATING, + git_project.url()))); }) test!(dep_with_submodule { -- 2.30.2